package lambdademo;

import java.util.Comparator;
import java.util.PriorityQueue;

//无返回值 一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}

//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}

//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}

//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}

public class Test {
    public static void main(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((o1,o2) -> o2.compareTo(o1));
    }
    public static void main8(String[] args) {
        int a = 10;
        //a = 10;//无法捕获
        NoParameterNoReturn noParameterNoReturn = () -> {
            //a = 20;//无法捕获
            System.out.println("捕获变量" + a);
            //a = 100;//无法捕获
        };

        //a = 15;//无法捕获
        noParameterNoReturn.test();
    }
    public static void main7(String[] args) {
        MoreParameterReturn moreParameterReturn = (a,b) -> a - b;
        System.out.println(moreParameterReturn.test(20, 10));;
    }
    public static void main6(String[] args) {
        OneParameterReturn oneParameterReturn = a -> a * 2;
        System.out.println(oneParameterReturn.test(10));
    }
    public static void mai5(String[] args) {
        NoParameterReturn noParameterReturn = () -> 10;

        System.out.println(noParameterReturn.test());
    }
    public static void main4(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = (a,b) -> System.out.println(a * b);

        moreParameterNoReturn.test(10,50);
    }
    public static void main3(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = a -> System.out.println(a);

        oneParameterNoReturn.test(100);
    }
    public static void main2(String[] args) {
        NoParameterNoReturn noParameterNoReturn =
                () -> System.out.println("使用接口。。。。。");
        noParameterNoReturn.test();
    }

    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("使用接口。。。。。");
            }
        };

        noParameterNoReturn.test();

    }
}
